<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="公司代码" prop="gcCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.gcCode"-->
<!--          placeholder="请输入公司代码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="公司名称" prop="gcName">-->
<!--        <el-input-->
<!--          v-model="queryParams.gcName"-->
<!--          placeholder="请输入公司名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="来访人姓名" prop="lfName">
        <el-input
          v-model="queryParams.lfName"
          placeholder="请输入来访人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="lfCard">
        <el-input
          v-model="queryParams.lfCard"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话号码" prop="lfPhone">
        <el-input
          v-model="queryParams.lfPhone"
          placeholder="请输入电话号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="单位" prop="lfDw">-->
<!--        <el-input-->
<!--          v-model="queryParams.lfDw"-->
<!--          placeholder="请输入单位"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="车牌号" prop="lfCar">-->
<!--        <el-input-->
<!--          v-model="queryParams.lfCar"-->
<!--          placeholder="请输入车牌号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="居住地" prop="lfAddress">-->
<!--        <el-input-->
<!--          v-model="queryParams.lfAddress"-->
<!--          placeholder="请输入居住地"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="体温测量" prop="lfTw">-->
<!--        <el-input-->
<!--          v-model="queryParams.lfTw"-->
<!--          placeholder="请输入体温测量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="被防人姓名" prop="bfName">-->
<!--        <el-input-->
<!--          v-model="queryParams.bfName"-->
<!--          placeholder="请输入被防人姓名"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="来访事由" prop="lfSy">-->
<!--        <el-input-->
<!--          v-model="queryParams.lfSy"-->
<!--          placeholder="请输入来访事由"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否携带物品 0&#45;&#45;否 1&#45;&#45;是" prop="isWp">-->
<!--        <el-input-->
<!--          v-model="queryParams.isWp"-->
<!--          placeholder="请输入是否携带物品 0&#45;&#45;否 1&#45;&#45;是"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="来访状态 1-进厂2- 出厂" prop="isState">-->
<!--        <el-input-->
<!--          v-model="queryParams.isState"-->
<!--          placeholder="请输入来访状态 1-进厂2- 出厂"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="来访日期" prop="lfDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.lfDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择来访日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="进厂时间" prop="jcTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.jcTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择进厂时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="出厂时间" prop="ccTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.ccTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择出厂时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否核实 0-未核实 1&#45;&#45;核实" prop="isSh">-->
<!--        <el-input-->
<!--          v-model="queryParams.isSh"-->
<!--          placeholder="请输入是否核实 0-未核实 1&#45;&#45;核实"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="${comment}" prop="createId">-->
<!--        <el-input-->
<!--          v-model="queryParams.createId"-->
<!--          placeholder="请输入${comment}"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="${comment}" prop="createDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.createDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择${comment}">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="${comment}" prop="modifyId">-->
<!--        <el-input-->
<!--          v-model="queryParams.modifyId"-->
<!--          placeholder="请输入${comment}"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="${comment}" prop="modifyDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.modifyDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择${comment}">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用1" prop="remark1">-->
<!--        <el-input-->
<!--          v-model="queryParams.remark1"-->
<!--          placeholder="请输入备用1"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用2" prop="remark2">-->
<!--        <el-input-->
<!--          v-model="queryParams.remark2"-->
<!--          placeholder="请输入备用2"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="备用3" prop="remark3">-->
<!--        <el-input-->
<!--          v-model="queryParams.remark3"-->
<!--          placeholder="请输入备用3"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:reg:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:reg:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:reg:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:reg:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="regList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="uuid" />
      <el-table-column label="公司代码" align="center" prop="gcCode" />
      <el-table-column label="公司名称" align="center" prop="gcName" />
      <el-table-column label="来访人姓名" align="center" prop="lfName" />
      <el-table-column label="证件号码" align="center" prop="lfCard" />
      <el-table-column label="电话号码" align="center" prop="lfPhone" />
      <el-table-column label="单位" align="center" prop="lfDw" />
      <el-table-column label="车牌号" align="center" prop="lfCar" />
      <el-table-column label="居住地" align="center" prop="lfAddress" />
      <el-table-column label="体温测量" align="center" prop="lfTw" />
      <el-table-column label="被防人姓名" align="center" prop="bfName" />
      <el-table-column label="来访事由" align="center" prop="lfSy" />
      <el-table-column label="是否携带物品" align="center" prop="isWp">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.reg_is_wp" :value="scope.row.isWp"/>
        </template>
      </el-table-column>
      <el-table-column label="来访状态" align="center" prop="isState">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.reg_is_state" :value="scope.row.isState"/>
        </template>
      </el-table-column>
      <el-table-column label="来访日期" align="center" prop="lfDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lfDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="进厂时间" align="center" prop="jcTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jcTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出厂时间" align="center" prop="ccTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ccTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否核实" align="center" prop="isSh">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.reg_is_sh" :value="scope.row.isSh"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
    <!--  <el-table-column label="${comment}" align="center" prop="createId" />
      <el-table-column label="${comment}" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="modifyId" />
      <el-table-column label="${comment}" align="center" prop="modifyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
     <!-- <el-table-column label="备用1" align="center" prop="remark1" />
      <el-table-column label="备用2" align="center" prop="remark2" />
      <el-table-column label="备用3" align="center" prop="remark3" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:reg:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:reg:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改园区系统对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司代码" prop="gcCode">
          <el-input v-model="form.gcCode" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="gcName">
          <el-input v-model="form.gcName" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="来访人姓名" prop="lfName">
          <el-input v-model="form.lfName" placeholder="请输入来访人姓名" />
        </el-form-item>
        <el-form-item label="证件号码" prop="lfCard">
          <el-input v-model="form.lfCard" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="电话号码" prop="lfPhone">
          <el-input v-model="form.lfPhone" placeholder="请输入电话号码" />
        </el-form-item>
        <el-form-item label="单位" prop="lfDw">
          <el-input v-model="form.lfDw" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="车牌号" prop="lfCar">
          <el-input v-model="form.lfCar" placeholder="请输入车牌号" />
        </el-form-item>
        <el-form-item label="居住地" prop="lfAddress">
          <el-input v-model="form.lfAddress" placeholder="请输入居住地" />
        </el-form-item>
        <el-form-item label="体温测量" prop="lfTw">
          <el-input v-model="form.lfTw" placeholder="请输入体温测量" />
        </el-form-item>
        <el-form-item label="被防人姓名" prop="bfName">
          <el-input v-model="form.bfName" placeholder="请输入被防人姓名" />
        </el-form-item>
        <el-form-item label="来访事由" prop="lfSy">
          <el-input v-model="form.lfSy" placeholder="请输入来访事由" />
        </el-form-item>
        <el-form-item label="是否携带物品" prop="isWp">
          <el-select v-model="form.isWp" placeholder="是否携带物品">
            <el-option
              v-for="dict in dict.type.reg_is_wp"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="来访状态" prop="isState">
          <el-select v-model="form.isState" placeholder="请选择来访状态">
            <el-option
              v-for="dict in dict.type.reg_is_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="来访日期" prop="lfDate">
          <el-date-picker clearable
            v-model="form.lfDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择来访日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="进厂时间" prop="jcTime">
          <el-date-picker clearable
            v-model="form.jcTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择进厂时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出厂时间" prop="ccTime">
          <el-date-picker clearable
            v-model="form.ccTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出厂时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否核实" prop="isSh">
          <el-select v-model="form.isSh" placeholder="请选择是否核实">
            <el-option
              v-for="dict in dict.type.reg_is_sh"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
       <!-- <el-form-item label="${comment}" prop="createId">
          <el-input v-model="form.createId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="createDate">
          <el-date-picker clearable
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="modifyId">
          <el-input v-model="form.modifyId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="modifyDate">
          <el-date-picker clearable
            v-model="form.modifyDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>-->
        <el-form-item label="备用1" prop="remark1">
          <el-input v-model="form.remark1" placeholder="请输入备用1" />
        </el-form-item>
        <el-form-item label="备用2" prop="remark2">
          <el-input v-model="form.remark2" placeholder="请输入备用2" />
        </el-form-item>
        <el-form-item label="备用3" prop="remark3">
          <el-input v-model="form.remark3" placeholder="请输入备用3" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listReg, getReg, delReg, addReg, updateReg } from "@/api/business/reg";
export default {
  name: "Reg",
  dicts: ['reg_is_wp','reg_is_state','reg_is_sh'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 园区系统表格数据
      regList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gcCode: null,
        gcName: null,
        lfName: null,
        lfCard: null,
        lfPhone: null,
        lfDw: null,
        lfCar: null,
        lfAddress: null,
        lfTw: null,
        bfName: null,
        lfSy: null,
        isWp: null,
        isState: null,
        lfDate: null,
        jcTime: null,
        ccTime: null,
        isSh: null,
        createId: null,
        createDate: null,
        modifyId: null,
        modifyDate: null,
        remark1: null,
        remark2: null,
        remark3: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询园区系统列表 */
    getList() {
      this.loading = true;
      listReg(this.queryParams).then(response => {
        this.regList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        uuid: null,
        gcCode: null,
        gcName: null,
        lfName: null,
        lfCard: null,
        lfPhone: null,
        lfDw: null,
        lfCar: null,
        lfAddress: null,
        lfTw: null,
        bfName: null,
        lfSy: null,
        isWp: null,
        isState: null,
        lfDate: null,
        jcTime: null,
        ccTime: null,
        isSh: null,
        remark: null,
        createId: null,
        createDate: null,
        modifyId: null,
        modifyDate: null,
        remark1: null,
        remark2: null,
        remark3: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.uuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加园区系统";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const uuid = row.uuid || this.ids
      getReg(uuid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改园区系统";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.uuid != null) {
            updateReg(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReg(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const uuids = row.uuid || this.ids;
      this.$modal.confirm('是否确认删除园区系统编号为"' + uuids + '"的数据项？').then(function() {
        return delReg(uuids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/reg/export', {
        ...this.queryParams
      }, `reg_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
